<?php

namespace App\Service\User\v1_2_2;

use App\Constants\ErrorCode;
use App\Model\User;
use App\Model\UserProfile;
use App\Service\User\UserBaseService;

/**
 * 用户搜索
 */
class UserSearchService extends UserBaseService
{
    protected function RoVerifyList()
    {
        return [
            'profile_id' => 'required|string'
        ];
    }

    public function handle()
    {
        $profileId = $this->request->input('profile_id', '');
        $profile = UserProfile::getInfoByProfileId($profileId);
        if (!$profile) return $this->setError(ErrorCode::USER_NOT_VALID, '找不到该用户～');
        $user = User::find($profile->user_id);
        if (!$user || $user->status == User::STATUS_CANCELLATTED) {
            return $this->setError(ErrorCode::USER_NOT_VALID, '该账号已经注销！');
        }
        return [
            'user_id' => $profile->user_id,
        ];
    }
}
